home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 6394 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.4 KB  |  70 lines

  1. Path: tech.cftnet.com!usenet
  2. From: ams@cftnet.com
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: problem initializing static member of a class.
  5. Date: Tue, 06 Feb 1996 21:11:36 GMT
  6. Organization: CFTnet
  7. Message-ID: <4f8fq2$5ll@tech.cftnet.com>
  8. References: <4eumvq$ko1@uwm.edu>
  9. NNTP-Posting-Host: ppp245_10.cftnet.com
  10. X-Newsreader: Forte Free Agent 1.0.82
  11.  
  12. kumbera@allmalt.cs.uwm.edu (Mike Kumbera) wrote:
  13.  
  14. >I'm having troubles getting a static initilaizer for a member
  15. > of a class working.  I want to declare a static array of pointers
  16. > to a class as a member of the class.
  17. >(If this is possible)
  18.  
  19. >The following code is a short example of what I'm trying to do:
  20.  
  21.  
  22. >------------------------------------------------------------
  23.  
  24. >#include <iostream.h>
  25. >class TEST
  26. >{
  27. >   // a static array of pointers to the class TEST
  28. >   static TEST *TEST_ptr[];
  29. >};
  30. >// initialize the static member (I can't get this working)
  31. >TEST *TEST::TEST_ptr[] = NULL;
  32. >main()
  33. >{
  34. >   TEST a;
  35. >}
  36.  
  37.  
  38. >------------------------------------------------------------
  39.  
  40. >When I compile the code with gcc I get:
  41. >help.C:10: invalid initializer
  42.  
  43. >ANY ideas would be appreciated...
  44.  
  45. >mkumbera@cs.uwm.edu (Michael Kumbera)
  46.  
  47.  
  48.  
  49. Try this...
  50.  
  51. class TEST
  52. {
  53.    // a static array of pointers to the class TEST
  54.    static TEST *TEST_ptr;
  55. };
  56.  
  57. // initialize the static member (I can't get this working)
  58. TEST *TEST::TEST_ptr = NULL;
  59.  
  60. main()
  61. {
  62.    TEST a;
  63. }
  64.  
  65.  
  66.  
  67.